import symbolsvc from './service/symbolsvc.js';
import LXCOM from '../common/common.js'
class SymbolINTF {
    constructor(canvas) {
        this.m_pCanvas = canvas;
        this.m_pService = new symbolsvc.SymbolSvc(canvas.getDataManager());
    }

    save() {
        this.m_pService.save();
    }

    setSelGraphsAsSymbol(mainType,symbolName, state,reserveUnitFlag) {
        var result = this.m_pService.makeSelGraphs2Symbol(mainType,symbolName, state);
        var symbolid = result.symbolid;
        var errMsg = result.errMsg;
        var symbolCnt = new LXCOM.LGXPoint();
        symbolCnt.setVal(result.sx, result.sy);
        let unitStrDatas = this.getSymbolJsonObj(symbolid);
        if (result > 0 && !reserveUnitFlag) {
            console.log(symbolCnt);
            //COperStepService *pService = m_pCanvas->getOperStepService();
            //m_pService->process4ReserveUnit(newSymbolID,state,symbolCnt,pService);
        }
        let iconURL = this.generateICON(symbolid,false);
        return { typeID: symbolid, name: symbolName, data: unitStrDatas, msg: errMsg ,iconURL};
    }

    getSymbolJsonObj(symbolid) {
        var symbolObj = {};
        var array = [];
        var symboUnitList = this.m_pService.m_tPreMemSymbolUnitInfoLst;
        for (var m in symboUnitList) {
            let unitObj = symboUnitList[m];
            var jsonoj = unitObj.toJson();
            array.push(jsonoj);
            console.log(jsonoj);
        }
        symbolObj["elements"] = array;
        var version = "v0.0.0.1";
        symbolObj["version"] = version;
        return symbolObj;
    }

    generateICON(symbolid){
        return this.m_pService.generateICON(symbolid);
    }

    generateAllICON(){
        this.m_pService.generateAllICON();
    }

    generateICON_local(){
        this.m_pService.generateICON_local();
    }
}

export default { SymbolINTF }